package com.gientech.pactera.deploy.controller;

import com.gientech.pactera.deploy.po.request.OrderPo;
import com.gientech.pactera.deploy.po.response.OrderDto;
import com.shoping.common.response.ResponseData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Random;

@Slf4j
@RestController
@RequestMapping("/api")
public class OrderController {

    @GetMapping("/order/{id}")
    public ResponseData<OrderDto> getOrder(@PathVariable("id") Integer id) {
        OrderDto orderDto = new OrderDto();
        orderDto.setId(id);
        orderDto.setTitle("12号仓库");
        orderDto.setDesc("这是第一个订单，ID = " + id);
        return ResponseData.build(orderDto);
    }

    @PostMapping("/order")
    public ResponseData<OrderDto> saveOrder(@RequestBody @Validated OrderPo orderPo) {
        log.info("保存订单，ID = " + orderPo);
        OrderDto orderDto = new OrderDto();
        BeanUtils.copyProperties(orderPo, orderDto);
        orderDto.setId(new Random().nextInt(100));
        return ResponseData.build(orderDto);
    }

}
